using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DealerPlatform.Domain;
using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;

namespace DealerPlatform.Service.ProductApp
{
    public partial class ProductService
    {
        public async Task<List<ProductSale>> GetProductSalesByProductNo(params string[] productNos)
        {
            // 使用参数化查询构建 SQL 查询
            var query = $@"SELECT * FROM ProductSales 
                            WHERE ProductNo IN ({string.Join(',', productNos.Select((_, i) => $"@p{i}"))})";

            // 执行查询并获取结果
            var sales = context.ProductSales
            .FromSqlRaw(query, productNos.Select((num, i) => new SqlParameter($"@p{i}", num)).ToArray())
            .ToList();
            return sales;//await productSaleRepo.GetListAsync(m => productNos.Contains(m.ProductNo));
        }
        
    }
}